package com.ryskoo.catering.employeetablerel.repository;

import com.ryskoo.catering.employeetablerel.domain.EmployeeTableRelPO;
import com.ryskoo.framework.core.repository.BasicJPAImpl;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class EmployeeTableRelJPAImpl extends BasicJPAImpl<EmployeeTableRelPO> implements IEmployeeTableRelRepository {
    @Override
    public EmployeeTableRelPO getByEmployeeAndTable(String employeeUuid, String tableUuid) {
        String hql = "select o from EmployeeTableRelPO o where o.employeeUuid = :employeeUuid and o.tableUuid = :tableUuid ";
        Query query = getH4Session().createQuery(hql);
        query.setString("employeeUuid",employeeUuid);
        query.setString("tableUuid",tableUuid);
        Object object = query.uniqueResult();
        if(null!=object){
            return (EmployeeTableRelPO) object;
        }
        return null;
    }

    /**
     * 根据台桌uuid查询关联的服务员uuid集合
     *
     * @param tableUuid
     * @return
     */
    @Override
    public List<String> getEmpUuids(String tableUuid) {
        String hql = "select o.employeeUuid from EmployeeTableRelPO o where o.tableUuid = :tableUuid ";
        Query query = getH4Session().createQuery(hql);
        query.setString("tableUuid",tableUuid);
        List<String> list = query.list();
        return list;
    }
}
